package cn.pa4j.mapper;

import cn.pa4j.entity.Live;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface H2Mapper {

    @Select("select * from live where userid = #{id}")
    List<Live> getLivesByUserId(String id);

    @Select("select * from live where roomid = #{id}")
    List<Live> getLivesByRoomId(String id);

    @Update("CREATE TABLE if not exists `live` (\n" +
            "  `userid` varchar(32) DEFAULT NULL,\n" +
            "  `roomid` varchar(32) DEFAULT NULL\n" +
            ") ENGINE=InnoDB DEFAULT CHARSET=utf8")
    void creatLive();

    void addLive(Live live);

    @Select("select * from live where userid = #{userId} and roomid = #{roomId}")
    List<Live> getLivesByUserIdAndRoomId(@Param("userId") String userId, @Param("roomId")String roomId);

    @Select("SELECT roomid FROM LIVE group by roomid")
    List<String> getAllRooms();

    @Update("delete from live where userid = #{userId} and roomid = #{roomId}")
    void cancleLive(@Param("userId") String userId, @Param("roomId")String roomId);
}
